package algorithm.sort;

import algorithm.sort.common.SortTestHelper;

import java.util.Arrays;

/**
 * @author bingo
 * @Description
 * @Date 2018/6/13
 */
public class SortCompare {

    public static void main(String[] args) {

        Integer[] insertArr =  SortTestHelper.generateRandomArray(1000000, 0, 100000);
        //Integer[] insertArr =  SortTestHelper.generateNearlyRandomArray(10000,10);
        Integer[] insertArr2 =  Arrays.copyOfRange(insertArr,0,insertArr.length-1);
        Integer[] selectArr =   Arrays.copyOfRange(insertArr,0,insertArr.length-1);
        Integer[] quickArr  = Arrays.copyOfRange(insertArr,0,insertArr.length-1);
        QuickSort quickSort = new QuickSort();
        InsertSort insertSort = new InsertSort();
        SelectSort selectSort = new SelectSort();


        long start = System.currentTimeMillis();
        insertSort.sort(insertArr);
        long end = System.currentTimeMillis();
        System.out.println(SortTestHelper.isSorted(insertArr));
        System.out.println("插入排序耗时:"+(end-start)+"ms");



        long start2 = System.currentTimeMillis();
        insertSort.sort2(insertArr2);
        long end2 = System.currentTimeMillis();
        System.out.println(SortTestHelper.isSorted(insertArr2));
        System.out.println("优化后插入排序耗时:"+(end2-start2)+"ms");

        long start3 = System.currentTimeMillis();
        selectSort.sort(selectArr);
        long end3 = System.currentTimeMillis();
        System.out.println(SortTestHelper.isSorted(selectArr));
        System.out.println("选择排序耗时:"+(end3-start3)+"ms");



        long start4 = System.currentTimeMillis();
        quickSort.sort(quickArr);
        long end4 = System.currentTimeMillis();
        System.out.println(SortTestHelper.isSorted(quickArr));
        System.out.println("快速排序耗时:"+(end4-start4)+"ms");


    }
}
